using UnityEngine;
using System.Collections;
using UnityEditor;

public class CatSpawn : MonoBehaviour 
{
	public Vector3[] positions = new Vector3[6];
	public GameObject cat1;
	public GameObject cat2;
	private int randomPosition;
	private int lastRandomPosition;
	public float timer;
	public float spawnTime;
	
	public Texture2D cursorTexture;
    Vector2 hotSpot = Vector2.zero;
	CursorMode cursorMode = CursorMode.Auto;
	
	void Start()
	{
		spawnTime = 5;
	}
	
	void Update () 
	{
		Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
		
		timer += Time.deltaTime;
		
		if(timer > spawnTime)
		{
			lastRandomPosition = randomPosition;
			randomPosition = Random.Range(0,6);
				
			while(lastRandomPosition == randomPosition)
			{
				randomPosition = Random.Range(0,6);
			}
				
			if(randomPosition == 0 || randomPosition == 1 || randomPosition == 2)
			{
				Instantiate(cat1, positions[randomPosition], Quaternion.Euler(90, 180, 0));
				timer = 0;
				
				if(spawnTime > 1)
				{
					spawnTime -= 0.3f;
				}
			}
			
			if(randomPosition == 3 || randomPosition == 4 || randomPosition == 5)
			{
				Instantiate(cat2, positions[randomPosition], Quaternion.Euler(90, 180, 0));
				timer = 0;
								
				if(spawnTime > 1)
				{
					spawnTime -= 0.3f;
				}
			}
		}
	}
}
